import { request } from "@/common/utils";
import type { ApiResponse, SignInEmailDTO, SignInSMSDTO, UserDTO, UserVO } from "../..";

/**
 * 发送手机验证码
 * @param phone 
 * @returns 
 */
export const sendSMSService = (phoneNumber: string | number): ApiResponse<null> => request({
  method: UserApi.SendSMSCode[0],
  url: UserApi.SendSMSCode[1],
  data: {
    phoneNumber
  }
})


/**手机验证码登录 */
export const signInSMSService = (data: SignInSMSDTO): ApiResponse<string> => request({
  method: UserApi.SignInSMS[0],
  url: UserApi.SignInSMS[1],
  data
})



/**发送邮箱验证码 */
export const sendEmailCodeService = (email: string): ApiResponse<null> => request({
  method: UserApi.SendEmailCode[0],
  url: UserApi.SendEmailCode[1],
  data: {
    email
  }
})

/**使用邮箱验证码登录 */
export const signInEmailService = (data: SignInEmailDTO): ApiResponse<string> => request({
  method: UserApi.SignInEmail[0],
  url: UserApi.SignInEmail[1],
  data
})



/**
 * 更新当前用户信息
 * @param userId 
 * @param data 
 * @returns 
 */
export const updateUserByTokenService = (data: UserDTO): ApiResponse<UserVO> => request({
  method: UserApi.UpdateUserById[0],
  url: UserApi.UpdateUserById[1],
  data
})




/**获取当前登录用户信息 */
export const getUserInfoByTokenService = (): ApiResponse<UserVO> => request({
  method: UserApi.GetUserByToken[0],
  url: UserApi.GetUserByToken[1],
})
